package dao.impl;

import dao.BaseDao.BaseDao;
import javabean.User;

import java.util.List;

public class UserDaoImpl extends BaseDao implements UserDao  {

    @Override
    public User queryUserByaccount(String account) {
        String sql = "select `id`,`account`,`password`,`role`,`regtime` from t_accounts where account = ?";
        return queryForOne(User.class, sql, account);
    }

    @Override
    public User queryUserByAccountAndPassword(String account, String password) {
        String sql = "select `id`,`account`,`password`,`role`,`regtime` from t_accounts where account = ? and password = ?";
        return queryForOne(User.class, sql, account,password);
    }

    @Override
    public int saveUser(User user) {
        String sql = "insert into t_accounts(`account`,`password`,`regtime`) values(?,?,?)";
        return update(sql, user.getAccount(),user.getPassword(),user.getRegtime());
    }

    @Override
    public List<User> queryUserListByRole(Integer role) {
       String sql = "select `id`,`account`,`password`,`role`,`regtime` from t_accounts where role = ?";
       return queryForList(User.class,sql,role);
    }

    @Override
    public User queryUserById(Integer Id) {
        String sql = "select `id`,`account`,`password`,`role`,`regtime` from t_accounts where id = ?";
        return queryForOne(User.class,sql,Id);
    }

    @Override
    public int deleteUserById(Integer Id) {
        String sql="delete from t_accounts where id = ?";
        return update(sql,Id);
    }
}
